package com.lupan.tomcatStudy.javaStudy.chapter16.threadNotify;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 说明：
 *
 * @author lupan
 * @version 2017/3/15 15:11
 */
public class VinThread extends Thread {

    private LockPojo lockPojo;
    private String threadName;
    //用于阻塞线程的锁
    private final Lock lock = new ReentrantLock();
    private final Condition condition = lock.newCondition();

    public VinThread(String threadName, LockPojo lockPojo) {
        super(threadName);
        this.threadName = threadName;
        this.lockPojo = lockPojo;
    }

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + ":正在运行。。。");
        execute();
    }

    private synchronized void execute() {
        for (int i = 0; i < 10000; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
